/*
Rilego - An easy Images 2 E-Book converter.
Copyright (C) 2011  Federico Improta (Kirys)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
package it.kirys.rilego.engine.loaders.imagesources;

import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 *
 * @author Federico Improta
 */
public abstract class AbstractImageSource implements IImageSource {

	ImageType type;
	SourceInfo info;
	SourceTransformation transformations;

	@Override
	public String getFullIdentifier() {
		return getLoader().generateSourceFullIdentifier(this);
	}

	@Override
	public ImageType getType() {
		return type;
	}

	@Override
	public SourceTransformation getTransformations() {
		return transformations;
	}

	@Override
	public SourceInfo getInfo(){
		synchronized (this.getLoader()) {
			if (info == null) {
				info = new SourceInfo(this);
			}
		}
		return info;
	}

	/**
	 * Simple method for loading an image from the source
	 * @return buffered image
	 * @throws IOException
	 */
	public BufferedImage loadImage() throws IOException {
		synchronized (this.getLoader()) {
			BufferedInputStream bstream = new BufferedInputStream(this.getStream());
			return ImageIO.read(bstream);
		}
	}//public BufferedImage loadImage() throws IOException

	public AbstractImageSource(ImageType type) {
		this.type = type;
		this.transformations = new SourceTransformation();
		this.info = null;

	}
}
